package com.abc.service.impl;

import com.abc.dao.UserDAO;
import com.abc.entity.User;
import com.abc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDAO userDAO;

    @Override
    public void register(User user) {
        user.setId(UUID.randomUUID().toString().toUpperCase());
        // 管理员(admin)、注册用户(user)、游客(2)
        user.setUserType("visitor"); // 注册时权限是[注册用户]
        userDAO.save(user);
    }

    @Override
    public User login(String username, String password) {
        return userDAO.login(username, password);
    }

    @Override
    public List<User> findAll() {
        return userDAO.findAll();
    }

    @Override
    public User find(String id) {
        return userDAO.find(id);
    }

    @Override
    public void update(User user) {
        userDAO.update(user);
    }
}
